package org.zfes.snowier.cloud.zbss.pmp.router.service.pub;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpProjectGroupDetailDto;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpProjectMemberDto;
import org.zfes.snowier.cloud.zbss.pmp.model.PmpProject;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpBugsService;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpProjectService;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpProjectVersionService;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpTasksService;
import org.zfes.snowier.cloud.zbss.pmp.service.IpmpProjectGroupService;
import org.zfes.snowier.core.data.ComboboVo;
import org.zfes.snowier.core.util.ZDateUtil;
import org.zfes.snowier.core.util.datex.WeekDate;
import org.zfes.snowier.web.controller.BaseController;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@Controller("org.zfes.snowier.cloud.zbss.pmp.router.service.pub.pmpProjectController")
@RequestMapping("/pmp/service/pub/pmpProject")
public class PmpProjectController extends BaseController {

    @Autowired
    private IPmpProjectService pmpProjectService;
    @Autowired
    private IpmpProjectGroupService pProjectGroupService;
    @Autowired
    private IPmpProjectVersionService pmpProjectVersionService;
    @Autowired
    private IPmpTasksService tasksService;
    @Autowired
    private IPmpBugsService bugsService;
    
    @RequestMapping(value="/loadProjectGroupDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadProjectGroupDetail(Long projectId){
        Optional<PmpProjectGroupDetailDto> ops = pProjectGroupService.loadProjectGroupMembers(projectId);
        return ajaxQuery("projectGroupDetail",ops);
    }
    
    
    @RequestMapping(value="/loadProjectGroupComboboVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadProjectGroupComboboVo(Long projectId){
    	List<ComboboVo> ops = pProjectGroupService.loadProjectGroupComboboVo(projectId);
    	 return ajaxQuery("comboboVo", ops);
    }
    
    @RequestMapping(value="/loadProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadProject(Long id){
        Optional<PmpProject> ops = pmpProjectService.loadPmpProjectById(id);
        LocalDateTime startDate=LocalDateTime.ofInstant(ops.get().getCreatetime().toInstant(), ZoneId.systemDefault()) ;
        List<WeekDate> weekList=ZDateUtil.getWeekList(startDate,LocalDateTime.now());
        return ajaxQuery("project",ops).put("weekList", weekList);
    }
    
    
    
    @RequestMapping(value="/loadProjectWeekPlan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadProjectWeekPlan(Long id,Date startDate,Date endDate){
    	//需求 进度
    	//任务进度
    	//bug 分布
    	
        Optional<PmpProject> ops = pmpProjectService.loadPmpProjectById(id);
        return ajaxQuery("project",ops);
    }
    
    
    @RequestMapping(value="/loadPmpProjectUserJoin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadPmpProjectUserJoin(){
        List<PmpProjectMemberDto> projectList=  pmpProjectService.loadUserPmpProjectList(SecurityUtil.getUserId().get());
        return ajaxQuery("projectList", projectList);
    }


	 @RequestMapping(value="/loadPmpProjectComboboVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	 public @ResponseBody  Object loadPmpProjectComboboVo(Boolean firstEmpty){
			 List<ComboboVo>  vo=pmpProjectService.loadComboboVo(firstEmpty);
		    return ajaxQuery("comboboVo", vo);
	 }


}
